package com.bi.exception;

import com.bi.common.ErrorCode;
import com.bi.common.ResultBean;
import com.bi.utils.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class AllExceptionHandler {

    /**
     * 处理业务抛出异常类
     *
     * @return
     * @author yanzhen
     **/
    @ExceptionHandler(BusineseException.class)
    public ResultBean busineseExceptionHandler(BusineseException e) {
        log.error("busineseException: ", e.getMessage());
        return ResultUtil.error(e.getCode(), e.getMsg(), e.getDecription());
    }

    /**
     * 处理所有异常类
     *
     * @return
     * @author yanzhen
     **/
    @ExceptionHandler(Exception.class)
    public ResultBean commonExceptionHandler(Exception e) {
        log.error("服务器 内部错误", e.getMessage());
        return ResultUtil.error(ErrorCode.SYSTEM_ERROR, e.getMessage());
    }

}
